﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;

namespace code
{
    class TheSqlConnection//本类用于建立数据库连接和查询数据
    {
        public MySqlConnection connection = GetConnection();
        static private MySqlConnection GetConnection()
        {
            string connString = "server=localhost;port=3306;database=danci;user=root;password=020613;";
            MySqlConnection connection = new MySqlConnection(connString);
            return connection;
        }
        public MySqlDataReader GetSqlDataReader()//查询单词
        {
            string sql = "SELECT words FROM `wordstable`;";
            MySqlCommand command = new MySqlCommand(sql, connection);
            connection.Open();
            MySqlDataReader dataReader = command.ExecuteReader();
            return dataReader;
        }
        public MySqlDataReader GetAnswer()//查询汉字答案
        {
            string sql = "SELECT answers FROM `wordstable`;";
            MySqlCommand command = new MySqlCommand(sql, connection);
            connection.Open();
            MySqlDataReader dataReader = command.ExecuteReader();
            return dataReader;
        }
    }
}
